package com.taobao.txc.common;

import io.netty.channel.nio.NioEventLoop;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.net.SocketAddress;
import java.util.Enumeration;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class d
{
  private static final InternalLogger a = InternalLoggerFactory.getInstance(NioEventLoop.class);
  private static volatile InetAddress b = null;
  private static final Pattern c = Pattern.compile("\\d{1,3}(\\.\\d{1,3}){3,5}$");
  
  public static String a(SocketAddress paramSocketAddress)
  {
    return a((InetSocketAddress)paramSocketAddress);
  }
  
  public static String a(InetSocketAddress paramInetSocketAddress)
  {
    return paramInetSocketAddress.getAddress().getHostAddress() + ":" + paramInetSocketAddress.getPort();
  }
  
  public static InetSocketAddress a(String paramString)
  {
    int i = paramString.indexOf(':');
    String str;
    int j;
    if (i > -1)
    {
      str = paramString.substring(0, i);
      j = Integer.parseInt(paramString.substring(i + 1));
    }
    else
    {
      str = paramString;
      j = 0;
    }
    return new InetSocketAddress(str, j);
  }
  
  public static long b(String paramString)
  {
    InetSocketAddress localInetSocketAddress = a(paramString);
    String[] arrayOfString = localInetSocketAddress.getAddress().getHostAddress().split("\\.");
    long l = 0L;
    l |= Long.valueOf(arrayOfString[0]).longValue() << 40;
    l |= Long.valueOf(arrayOfString[1]).longValue() << 32;
    l |= Long.valueOf(arrayOfString[2]).longValue() << 24;
    l |= Long.valueOf(arrayOfString[3]).longValue() << 16;
    l |= localInetSocketAddress.getPort();
    return l;
  }
  
  public static String a()
  {
    InetAddress localInetAddress = c();
    return localInetAddress == null ? "127.0.0.1" : localInetAddress.getHostAddress();
  }
  
  public static String b()
  {
    InetAddress localInetAddress = c();
    return localInetAddress == null ? "localhost" : localInetAddress.getHostName();
  }
  
  public static InetAddress c()
  {
    if (b != null) {
      return b;
    }
    InetAddress localInetAddress = d();
    b = localInetAddress;
    return localInetAddress;
  }
  
  private static InetAddress d()
  {
    InetAddress localInetAddress1 = null;
    try
    {
      localInetAddress1 = InetAddress.getLocalHost();
      if (a(localInetAddress1)) {
        return localInetAddress1;
      }
    }
    catch (Throwable localThrowable1)
    {
      a.warn("Failed to retriving ip address, " + localThrowable1.getMessage(), localThrowable1);
    }
    try
    {
      Enumeration localEnumeration1 = NetworkInterface.getNetworkInterfaces();
      if (localEnumeration1 != null) {
        while (localEnumeration1.hasMoreElements()) {
          try
          {
            NetworkInterface localNetworkInterface = (NetworkInterface)localEnumeration1.nextElement();
            Enumeration localEnumeration2 = localNetworkInterface.getInetAddresses();
            if (localEnumeration2 != null) {
              while (localEnumeration2.hasMoreElements()) {
                try
                {
                  InetAddress localInetAddress2 = (InetAddress)localEnumeration2.nextElement();
                  if (a(localInetAddress2)) {
                    return localInetAddress2;
                  }
                }
                catch (Throwable localThrowable4)
                {
                  a.warn("Failed to retriving ip address, " + localThrowable4.getMessage(), localThrowable4);
                }
              }
            }
          }
          catch (Throwable localThrowable3)
          {
            a.warn("Failed to retriving ip address, " + localThrowable3.getMessage(), localThrowable3);
          }
        }
      }
    }
    catch (Throwable localThrowable2)
    {
      a.warn("Failed to retriving ip address, " + localThrowable2.getMessage(), localThrowable2);
    }
    a.error("Could not get local host ip address, will use 127.0.0.1 instead.");
    return localInetAddress1;
  }
  
  private static boolean a(InetAddress paramInetAddress)
  {
    if ((paramInetAddress == null) || (paramInetAddress.isLoopbackAddress())) {
      return false;
    }
    String str = paramInetAddress.getHostAddress();
    return (str != null) && (!"0.0.0.0".equals(str)) && (!"127.0.0.1".equals(str)) && (c.matcher(str).matches());
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.common.d
 * JD-Core Version:    0.7.0.1
 */